import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';

//设置axios的baseURL
axios.defaults.baseURL = 'http://localhost:3001';
axios.defaults.withCredentials = true;

//请求拦截处理
axios.interceptors.request.use(function (config) {
  axios.defaults.timeout = 1000;

  return config;
}, function (error) {
  return Promise.reject(error);
});

//响应拦截处理
axios.interceptors.response.use(function (response) {
  console.log('success')
  return response;
}, function (error) {
  if(error.response.status === 500) {
    alert(`服务端错误！code=${error.response.status}`)
}
  return Promise.reject(error);
});

//自己封装的axios
const myInstance = axios.create({
  baseURL:'http://localhost:3000',
  timeout:1000
})

Vue.config.productionTip = false

//将axios添加到Vue构造函数上
Vue.prototype.$axios = axios
Vue.prototype.$myInstance = myInstance

Vue.use(ElementUI)

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')